var page="1";
var pageSize="10";
var table;
var layer;
var fileId,fpath;
$(function () {
    sessionStorage.setItem("sharedFilepath","");
    getRecommendFiles(sessionStorage.getItem("id"));
    getTop10Files(sessionStorage.getItem("id"));
    //获取表格数据
    getSharedFilesList();

    layui.use('form', function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    })
})
/**
 * 查询推荐文件
 */
function getRecommendFiles(id) {
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectRecommendFiles",
        method: "post",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(id),
        success: function (res) {
            if(res.length > 0){
                for(let i=0;i<res.length;i++){
                    let str = "<div class=\"layui-inline\"><a onclick=\"getSharedFile("+res[i].fileId+")\" style=\"color: #1E9FFF\">"+res[i].fileName+"</a></div>"
                    $("#recommendFiles").append(str);
                }
            } else {
                let str = "<div class=\"layui-inline\"><a style=\"color: #1E9FFF\">暂无推荐</a></div>"
                $("#recommendFiles").append(str);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}
/**
 * 查询Top10
 */
function getTop10Files(id) {
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectTop10Files",
        method: "post",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(id),
        success: function (res) {
            if (res.length <1) {
                let str = "<li class=\"list-item\"><span class=\"title\"><p class=\"test\" style=\"color: #1E9FFF;\" >暂无文件</p></span></li>";
                $("#top10").append(str);
            } else {
                for(let i=0;i<res.length;i++){
                    let str = "<li class=\"list-item\"><span class=\"title\"><p class=\"test\" onclick=\"getSharedFile("+res[i].fileId+")\" style=\"color: #1E9FFF;\"  title=\""+res[i].fileName+"\">"+res[i].fileName+" &ensp; "+res[i].makeTime+"</p></span></li>";
                    $("#top10").append(str);
                }
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}


/**
 * 后台返回数据填充表格 demo
 */
function getSharedFile(fileId) {
    let sharedFile={};
    sharedFile.curPage=page;
    sharedFile.pageSize=pageSize;
    sharedFile.userId=fileId;
    debugger
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFilesList",
        method: "post",
        dataType: "text",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(sharedFile),
        success: function (res) {
            res = JSON.parse(res);
            sfrenderTable(res);
            renderpage1(res);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}
/**
 * 后台返回数据填充表格 demo
 */
function getSharedFilesList() {
    $("#getf1").hide();
    $("#getf2").hide();
    $("#gets1").show();
    $("#gets2").show();
    let sharedFile={};
    sharedFile.curPage=page;
    sharedFile.pageSize=pageSize;
    sharedFile.userId=sessionStorage.getItem("id");
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFileList",
        method: "post",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(sharedFile),
        success: function (res) {
            if (sessionStorage.getItem("fileGroup") == 1){
                renderTable1(res);
            } else {
                renderTable2(res);
            }
            renderpage(res);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}

/**
 * 模糊查询共享组
 */
function getFilesList() {
    let sharedFile={};
    sharedFile.curPage=page;
    sharedFile.pageSize=pageSize;
    sharedFile.userId=sessionStorage.getItem("id");
    sharedFile.sharedfileName = $("#filename").val();
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFileList",
        method: "post",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(sharedFile),
        success: function (res) {
            if (sessionStorage.getItem("fileGroup") == 1){
                renderTable1(res);
            } else {
                renderTable2(res);
            }
            renderpage(res);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}
/**
 * 模糊查询共享组
 */
function getSharedFilesListM() {
    let sharedFile={};
    if(sessionStorage.getItem("sharedFilepath")!=""){
        sharedFile.sharedfilePath=sessionStorage.getItem("sharedPath")+"/"+sessionStorage.getItem("sharedFilepath")+"/";
    }else {
        sharedFile.sharedfilePath=sessionStorage.getItem("sharedPath")+"/";
    }
    sharedFile.id=sessionStorage.getItem("sharedFileId");
    sharedFile.curPage=page;
    sharedFile.pageSize=pageSize;
    sharedFile.sharedfileName = $("#filename1").val();
    debugger
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFilesList",
        method: "post",
        dataType: "text",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(sharedFile),
        success: function (res) {
            res = JSON.parse(res);
            debugger
            sfrenderTable(res);
            renderpage1(res);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}

/**
 * 表格渲染
 */
function renderTable1(data) {
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#allFilesTable'
            ,url: '../../admin/data/common.json'
            , page: false
            , height: 400
            ,toolbar: '#toolbar1' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['exports', 'print']
            , parseData: function (res) {
                return {
                    "code": 0,
                    "msg": "",
                    "data": data.data
                }
            }
            , cols: [[
                {field: 'type',width:100,title: '图标', templet:function (data) {
                        return '<i class="layui-icon layui-icon-tabs" style="font-size: 30px;"></i>';
                    }}
                , {field: 'sharedfileName', title: '文件组名',sort:true, templet: function (data) {
                        return "<a href='javascript:void(0)' style='color: #1aa5fb'"+" onclick=openFile('" + data.id +"','"+data.sharedfilePath+ "')>" + data.sharedfileName + "</a>";
                    }}
                , {field: 'createTime', title: '创建时间',sort:true, templet: function (data) {
                        return data.createTime;
                    }}
                , {fixed: 'right', title: '操作',templet:function (data) {
                    if (data.createPeople == sessionStorage.getItem("id")){
                        var btns = "";
                        btns += ' <a class="layui-btn layui-btn-xs " lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
                        btns += ' <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                        return btns;
                    } else {
                        var btns = "";
                        btns += ' <a class="layui-btn layui-btn-xs " lay-event="see"><i class="layui-icon layui-icon-tips"></i>查看</a>';
                        return btns;
                    }
                }}
            ]]
        });

        //监听行工具事件
        table.on('tool(allFilesDemo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete'){
                layer.confirm('真的删除该共享文件组吗？', function(index){
                    deleteFile(data.id);
                    obj.del();
                });
            }else if(obj.event === 'edit'){
                //弹窗
                layui.use('layer', function () { //独立版的layer无需执行这一句
                    var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
                    layer.open({
                        type: 2,
                        title: '共享文件组详情',
                        skin: 'layui-layer-molv', //样式类名
                        shade: 0.8,
                        shadeClose:false,
                        area: ['70%', '80%'],
                        content: 'editSharedFile.html',
                        success: function (layero, index) {
                            var body = layui.layer.getChildFrame('body', index);
                            //获取新窗口对象
                            var iframeWindow = layero.find('iframe')[0].contentWindow;
                            //父页面传下拉框的选择值，然后显示
                            iframeWindow.child(obj.data.id);
                        },
                        end: function () {
                            getSharedFilesList()
                        }
                    });
                });
            }else if(obj.event === 'see'){
                //弹窗
                layui.use('layer', function () { //独立版的layer无需执行这一句
                    var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
                    layer.open({
                        type: 2,
                        title: '共享文件组详情',
                        skin: 'layui-layer-molv', //样式类名
                        shade: 0.8,
                        shadeClose:false,
                        area: ['70%', '80%'],
                        content: 'seeSharedFile.html',
                        success: function (layero, index) {
                            var body = layui.layer.getChildFrame('body', index);
                            //获取新窗口对象
                            var iframeWindow = layero.find('iframe')[0].contentWindow;
                            //父页面传下拉框的选择值，然后显示
                            iframeWindow.child(obj.data.id);
                        }
                    });
                });
            }
        });
    });
}

/**
 * 表格渲染
 */
function renderTable2(data) {
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#allFilesTable'
            ,url: '../../admin/data/common.json'
            , page: false
            , height: 400
            ,defaultToolbar: ['exports', 'print']
            , parseData: function (res) {
                return {
                    "code": 0,
                    "msg": "",
                    "data": data.data
                }
            }
            , cols: [[
                {field: 'type',width:100,title: '图标', templet:function (data) {
                        return '<i class="layui-icon layui-icon-tabs" style="font-size: 30px;"></i>';
                    }}
                , {field: 'sharedfileName', title: '文件组名',sort:true, templet: function (data) {
                        return "<a href='javascript:void(0)' style='color: #1aa5fb'"+" onclick=openFile('" + data.id +"','"+data.sharedfilePath+ "')>" + data.sharedfileName + "</a>";
                    }}
                , {field: 'createTime', title: '创建时间',sort:true, templet: function (data) {
                        return data.createTime;
                    }}
                , {fixed: 'right', title: '操作',templet:function (data) {
                    var btns = "";
                    btns += ' <a class="layui-btn layui-btn-xs " lay-event="see"><i class="layui-icon layui-icon-tips"></i>查看</a>';
                    return btns;
                }}
            ]]
        });
        //监听行工具事件
        table.on('tool(allFilesDemo)', function (obj) {
            if(obj.event === 'see'){
                //弹窗
                layui.use('layer', function () { //独立版的layer无需执行这一句
                    var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
                    layer.open({
                        type: 2,
                        title: '共享文件组详情',
                        skin: 'layui-layer-molv', //样式类名
                        shade: 0.8,
                        shadeClose:false,
                        area: ['70%', '80%'],
                        content: 'seeSharedFile.html',
                        success: function (layero, index) {
                            var body = layui.layer.getChildFrame('body', index);
                            //获取新窗口对象
                            var iframeWindow = layero.find('iframe')[0].contentWindow;
                            //父页面传下拉框的选择值，然后显示
                            iframeWindow.child(obj.data.id);
                        }
                    });
                });
            }
        });
    });
}


/**
 * 分页
 */
function renderpage(date) {
    layui.use('laypage', function () {
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'allFilesTable_page' //注意，这里的 test1 是 ID，不用加 # 号
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , count: date.total //数据总数，从服务端得到
            , limits: [10,20, 30]
            , curr: page
            , limit: pageSize
            , jump: function (obj, first) {
                //首次不执行
                if (!first) {
                    page = obj.curr;
                    pageSize = obj.limit;
                    getSharedFilesList();
                }
            }
        });

    });
}

/**
 * 删除共享组
 */
function deleteFile(id) {
    var sharedFile = {};
    sharedFile.id=id;
    sharedFile.state=0;
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/update",
        data:JSON.stringify(sharedFile),
        dataType:'json',
        contentType: 'application/json;charset=utf-8',
        type:'post',
        success:function(res){
            if(res==1){
                layer.msg("删除共享文件组成功",{icon:0,time:1000});
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg("删除共享文件组失败！" ,{icon:2,time:1000});
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}

/**
 * 新建共享组
 */
function addFloder() {
    layui.use('layer', function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
        layer.open({
            type: 2,
            title: '新增共享文件组',
            skin: 'layui-layer-molv', //样式类名
            shade: 0.8,
            shadeClose:false,
            area: ['70%', '80%'],
            content: 'addSharedFile.html',
            end: function () {
                getSharedFilesList()
            }
        });
    });
}


/**
 * 新建文件夹
 */
function addSFloder() {
    layui.use('layer', function () { //独立版的layer无需执行这一句
        var $ = layui.jquery; layer = layui.layer; //独立版的layer无需执行这一句
        layer.prompt({title: '输入文件夹名称', formType: 2}, function(fileName, index){
            var obsFile={};
            obsFile.userId=sessionStorage.getItem("id");
            obsFile.fileName=fileName;
            obsFile.sharedId=sessionStorage.getItem("sharedFileId");
            if(sessionStorage.getItem("sharedFilepath")!=""){
                obsFile.path=sessionStorage.getItem("sharedPath")+"/"+sessionStorage.getItem("sharedFilepath")+"/"+fileName;
            }else {
                obsFile.path=sessionStorage.getItem("sharedPath")+"/"+fileName;
            }
            $.ajax({
                url: sessionStorage.getItem("rootPath") + "/sharedFiles/addFloder",
                data:JSON.stringify(obsFile),
                dataType:'json',
                contentType: 'application/json;charset=utf-8',
                type:'post',
                success:function(res){
                    layer.msg("创建文件夹成功！",{icon:1,time:1000},function () {
                        getSharedFileList();
                        layer.close(index);
                    });
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg("创建失败！" ,{icon:2,time:1000});
                    console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
                }
            })
        });
    });
}

/**
 * 打开共享组
 */
function openFile(id,path) {
    $("#gets1").hide();
    $("#gets2").hide();
    $("#getf1").show();
    $("#getf2").show();
    sessionStorage.setItem("sharedFileId",id);
    sessionStorage.setItem("sharedPath",path);
    getSharedFileList();
}

/**
 * 读取改共享组的文件列表
 * @param id
 */
function getSharedFileList() {
    //查询共享组下的文件
    let sharedFile={};
    if(sessionStorage.getItem("sharedFilepath")!=""){
        sharedFile.sharedfilePath=sessionStorage.getItem("sharedPath")+"/"+sessionStorage.getItem("sharedFilepath")+"/";
    }else {
        sharedFile.sharedfilePath=sessionStorage.getItem("sharedPath")+"/";
    }
    sharedFile.id=sessionStorage.getItem("sharedFileId");
    sharedFile.curPage=page;
    sharedFile.pageSize=pageSize;
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFilesList",
        method: "post",
        dataType: "text",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(sharedFile),
        success: function (res) {
            res = JSON.parse(res);
            sfrenderTable(res);
            renderpage1(res);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}

/**
 * 分页
 */
function renderpage1(date) {
    layui.use('laypage', function () {
        var laypage = layui.laypage;
        //执行一个laypage实例
        laypage.render({
            elem: 'allFilesTable_page' //注意，这里的 test1 是 ID，不用加 # 号
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , count: date.total //数据总数，从服务端得到
            , limits: [10,20, 30]
            , curr: page
            , limit: pageSize
            , jump: function (obj, first) {
                //首次不执行
                if (!first) {
                    page = obj.curr;
                    pageSize = obj.limit;
                    getSharedFileList();
                }
            }
        });

    });
}
/**
 * 表格渲染
 */
function sfrenderTable(data) {
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#allFilesTable'
            ,url: '../../admin/data/common.json'
            , page: false
            , height: 400
            ,toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['exports', 'print']
            , parseData: function (res) {
                return {
                    "code": 0,
                    "msg": "",
                    "data": data.data
                }
            }
            , cols: [[
                {type:'checkbox',width:50},
                {field: 'type',width:100,title: '图标', templet:function (data) {
                        if(data.type=="图片"){
                            return '<i class="layui-icon layui-icon-picture" style="font-size: 30px;"></i>';
                        }else if(data.type=="文档"){
                            return '<i class="layui-icon layui-icon-list" style="font-size: 30px;"></i>';
                        }else if(data.type=="音乐"){
                            return '<i class="layui-icon layui-icon-headset" style="font-size: 30px;"></i>';
                        }else if(data.type=="视频"){
                            return '<i class="layui-icon layui-icon-video" style="font-size: 30px;"></i>';
                        }else if(data.type=="文件夹"){
                            return '<i class="layui-icon layui-icon-tabs" style="font-size: 30px;"></i>';
                        }else if(data.type=="其他"){
                            return '<i class="layui-icon layui-icon-file" style="font-size: 30px;"></i>';
                        }
                    }}
                , {field: 'fileName', title: '文件名',sort:true, templet: function (data) {
                        return "<a style='color: #1aa5fb'"+" onclick=opensFile('" + data.path + "','"+data.type+ "','"+data.fileId+"')>" + data.fileName + "</a>";
                    }}
                , {field: 'size', title: '文件大小',sort:true, templet: function (data) {
                        if(data.type=="文件夹"){
                            return "--";
                        }else {
                            return data.size;
                        }
                    }}
                , {field: 'makeTime', title: '上传时间',sort:true, templet: function (data) {
                        if(data.type=="文件夹"){
                            return "--";
                        }else {
                            return data.makeTime;
                        }
                    }}
                , {fixed: 'right', title: '操作',templet:function (data) {
                        var btns = "";
                        btns += ' <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                        btns += ' <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="preview"><i class="layui-icon layui-icon-refresh"></i>重命名</a>';
                        return btns;
                    }}
            ]]
        });

        //监听行工具事件
        table.on('tool(allFilesDemo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete'){
                layer.confirm('真的删除该文件/文件夹吗？', function(index){
                    deleteSharedFile(data.fileId,data.path,data.type);
                    obj.del();
                });
            }else if(obj.event === 'preview'){
                var data = obj.data;
                if(data.type=="文件夹"){
                    layer.msg("文件夹暂时不能重命名哦！")
                }else{
                    layer.prompt({title: '输入新名称', formType: 0,value:data.fileName},function(fileName, index){
                        var obsFile={};
                        obsFile.userId=sessionStorage.getItem("id");
                        obsFile.fileName=data.path;
                        obsFile.fileId=data.fileId;
                        obsFile.path=data.path.substring(0,data.path.length-data.fileName.length)+fileName;
                        $.ajax({
                            url: sessionStorage.getItem("rootPath") + "/sharedFiles/rename",
                            data:JSON.stringify(obsFile),
                            dataType:'json',
                            contentType: 'application/json;charset=utf-8',
                            type:'post',
                            success:function(res){
                                if (res ==1){
                                    layer.msg("重命名成功！",{icon:1,time:1000},function () {
                                        getSharedFileList();
                                        layer.close(index);
                                    });
                                }else {
                                    layer.msg("文件已存在！",{icon:2,time:1000},function () {
                                        getSharedFileList();
                                        layer.close(index);
                                    });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.msg("重命名失败！" ,{icon:2,time:1000});
                                console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
                            }
                        })
                    });
                }
            }
        });
    });
}

/**
 * 删除共享组的文件
 */
function deleteSharedFile(id,path,type) {
    var obsFile = {};
    obsFile.fileId=id;
    obsFile.path=path;
    obsFile.sharedId=sessionStorage.getItem("sharedFileId");
    obsFile.type=type;
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/deleteFile",
        data:JSON.stringify(obsFile),
        dataType:'json',
        contentType: 'application/json;charset=utf-8',
        type:'post',
        success:function(res){
            if(res==0){
                layer.msg("该文件夹内含有文件，请先删除文件后重试！",{icon:0,time:1000});
            }else{
                layer.msg("删除文件/文件夹成功！",{icon:1,time:1000});
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg("删除文件/文件夹失败！" ,{icon:2,time:1000});
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}

/**
 * 下载文件
 */
function ObsDownload() {
    let checkStatus=table.checkStatus("allFilesTable");
    if(checkStatus.data.length>0){
        //遍历下载
        for(var i=0;i<checkStatus.data.length;i++){
            if(checkStatus.data[i].type!="文件夹"){
                var obsFile={};
                obsFile.userId=sessionStorage.getItem("id");
                obsFile.fileId=checkStatus.data[i].fileId;
                $.ajax({
                    url: sessionStorage.getItem("rootPath") + "/sharedFiles/addDownLoadLog",
                    method: "post",
                    dataType: "text",
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify(obsFile),
                    success: function (res) {
                        addHeat(obsFile.fileId,"1");
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
                    }
                })
                let res = "https://sss-0.obs.cn-east-3.myhuaweicloud.com/"+checkStatus.data[i].path+'?response-content-disposition=attachment';
                window.open(res,"_blank");
            }else{
                layer.msg("文件夹暂时不支持下载！")
            }
        }
    }else {
        layui.use('layer', function() { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            layer.alert('请至少选择一个文件');
        })
    }
}

/**
 * 打开文件
 */
function opensFile(path,type,fileId) {
    if(type=="图片" || type=="视频" || type=="音乐"){
        var obsFile={};
        obsFile.userId=0;
        obsFile.path=path;
        $.ajax({
            url: sessionStorage.getItem("rootPath") + "/files/preview",
            method: "post",
            dataType: "text",
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(obsFile),
            success: function (res) {
                //预览日志
                var obsFile={};
                obsFile.userId=sessionStorage.getItem("id");
                obsFile.fileId=fileId;
                $.ajax({
                    url: sessionStorage.getItem("rootPath") + "/sharedFiles/addPreviewLog",
                    method: "post",
                    dataType: "text",
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify(obsFile),
                    success: function (res) {
                        addHeat(fileId,"2");
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
                    }
                })
                window.open(res,"_blank");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
            }
        })
    }else if(type=="文件夹")
    {
        let sharedFile={};
        sharedFile.sharedfilePath=path+"/";
        sharedFile.id=sessionStorage.getItem("sharedFileId");
        sharedFile.curPage=page;
        sharedFile.pageSize=pageSize;
        $.ajax({
            url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFilesList",
            method: "post",
            dataType: "text",
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(sharedFile),
            success: function (res) {
                res = JSON.parse(res);
                let arr = path.split("/");
                arr.splice(0,1);
                path = arr.join("/");
                sessionStorage.setItem("sharedFilepath",path);
                debugger
                sfrenderTable(res);
                renderpage1(res);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
            }
        })
    }else{
        layui.use('layer', function() { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            layer.alert('该文件暂时不支持预览！');
        })
    }
}

/**
 * 添加互动热度
 *
 */
function addHeat(fileId,flag) {
    let heatRecord = {};
    heatRecord.fileId = fileId;
    heatRecord.flag = flag;
    $.ajax({
        url: sessionStorage.getItem("rootPath") + "/sharedFiles/addHinteractRecord",
        method: "post",
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        data: JSON.stringify(heatRecord),
        success: function (res) {

        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
        }
    })
}


/**
 * 返回上一级
 */
function back() {
    let path = sessionStorage.getItem("sharedPath")+"/"+sessionStorage.getItem("sharedFilepath");
    let obsFile = {};
    obsFile.userId = sessionStorage.getItem("id");
    if(sessionStorage.getItem("sharedFilepath") == null || sessionStorage.getItem("sharedFilepath") == ""){
        getSharedFilesList();
    }else {
        let sharedFile={};
        let arr = path.split("/");
        arr.pop();
        if(arr.length>0){
            path= arr.join("/");
            sharedFile.sharedfilePath = path+"/";
        } else {
            path = "";
        }
        sharedFile.curPage=page;
        sharedFile.pageSize=pageSize;
        sharedFile.id=sessionStorage.getItem("sharedFileId");
        $.ajax({
            url: sessionStorage.getItem("rootPath") + "/sharedFiles/selectSharedFilesList",
            method: "post",
            dataType: "json",
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(sharedFile),
            success: function (res) {
                let arr = path.split("/");
                arr.splice(0,1);
                path = arr.join("/");
                debugger
                sessionStorage.setItem("sharedFilepath", path);
                sfrenderTable(res);
                renderpage(res);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("失败" + XMLHttpRequest.status + ":" + textStatus + ":" + errorThrown);
            }
        })
    }
}


/**
 * 复制
 */
function ObsCopy() {
    let checkStatus=table.checkStatus("allFilesTable");
    if(checkStatus.data.length==1){
        if(checkStatus.data[0].type=="文件夹"){
            layer.msg("文件夹暂时不能复制哦！")
        }else{
            var  fileId= checkStatus.data[0].fileId;
            var  path= checkStatus.data[0].path;
            var  name= checkStatus.data[0].fileName;
            layui.use('layer', function () { //独立版的layer无需执行这一句
                var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
                layer.open({
                    type: 2,
                    title: '复制文件',
                    skin: 'layui-layer-molv', //样式类名
                    shade: 0.8,
                    shadeClose:false,
                    area: ['50%', '70%'],
                    content: 'sharedCopyFile.html',
                    success: function (layero, index) {    //成功获得加载changefile.html时，预先加载，将值从父窗口传到 子窗口
                        let body = layer.getChildFrame('body', index);
                        body.find("#fileId").val(fileId+","+path+","+name);
                        layui.form.render();
                    }
                });
            });
        }
    }else{
        layui.use('layer', function() { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            layer.alert('请选择一个文件');
        })
    }

}


/**
 * 移动
 */
function ObsMove() {
    let checkStatus=table.checkStatus("allFilesTable");
    if(checkStatus.data.length==1){
        if(checkStatus.data[0].type=="文件夹") {
            layer.msg("文件夹暂时不能移动哦！")
        }else{
            var  fileId= checkStatus.data[0].fileId;
            var  path= checkStatus.data[0].path;
            var  name= checkStatus.data[0].fileName;
            layui.use('layer', function () { //独立版的layer无需执行这一句
                var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
                layer.open({
                    type: 2,
                    title: '移动文件',
                    skin: 'layui-layer-molv', //样式类名
                    shade: 0.8,
                    shadeClose:false,
                    area: ['50%', '70%'],
                    content: 'moveSharedFile.html',
                    success: function (layero, index) {    //成功获得加载changefile.html时，预先加载，将值从父窗口传到 子窗口
                        let body = layer.getChildFrame('body', index);
                        body.find("#fileId").val(fileId+","+path+","+name);
                        layui.form.render();
                    }
                });
            });
        }
    }else{
        layui.use('layer', function() { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            layer.alert('请选择一个文件');
        })
    }
}